import type {
  DatePickerProps,
  ISelectProps,
  TimePickerDefaultProps,
  RadioProps,
  RateProps,
  SliderProps,
  SwitchProps,
  ColorPickerProps,
} from 'element-plus';

type searchTypeProps =
  | 'input'
  | 'select'
  | 'datepicker'
  | 'select2'
  | 'timepicker'
  | 'datetime'
  | 'treeselect'
  | 'cascader'
  | 'radio'
  | 'rate'
  | 'slider'
  | 'switch'
  | 'upload'
  | 'checkbox'
  | 'color';

interface IOptions {
  label: string;
  value: string | number;
  children?: Array<IOptions>;
  [key: string]: any;
}

type OtherProps<T extends searchTypeProps> = T extends 'datepicker'
  ? Partial<DatePickerProps>
  : T extends 'select2'
  ? Partial<ISelectProps>
  : T extends 'timepicker'
  ? Partial<TimePickerDefaultProps>
  : T extends 'radio'
  ? Partial<RadioProps>
  : T extends 'rate'
  ? Partial<RateProps>
  : T extends 'slider'
  ? Partial<SliderProps>
  : T extends 'switch'
  ? Partial<SwitchProps>
  : T extends 'color'
  ? Partial<ColorPickerProps>
  : any;

export interface IListPropsItem<K = true, T extends searchTypeProps = 'input'> {
  label: string;
  prop: K extends Boolean ? string : keyof K;
  fieldType: searchTypeProps;
  labelWidth?: string;
  extra?: string;
  options?: Array<IOptions>;
  otherProps?: OtherProps<T>;
  callback?: (val: any) => void;
  isShowCheckAll?: boolean;
  checkAll?: boolean;
  isIndeterminate?: boolean;
  [key: string]: any;
}

export type IListPropsType<T = true> = Array<
  | IListPropsItem<T>
  | IListPropsItem<T, 'datepicker'>
  | IListPropsItem<T, 'select2'>
  | IListPropsItem<T, 'timepicker'>
  | IListPropsItem<T, 'radio'>
  | IListPropsItem<T, 'rate'>
  | IListPropsItem<T, 'slider'>
  | IListPropsItem<T, 'switch'>
  | IListPropsItem<T, 'color'>
>;

export type dictPropsType = {
  [key: string]: Array<IOptions>;
};
